package com.gao.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Projectname springboot-redis
 * @Filename RedisController
 * @Author an
 * @Data 2022/8/18 22:08
 * @Description TODO
 */
@RestController
@RequestMapping("/redisTest")
public class RedisController {


    @Autowired
    private RedisTemplate redisTemplate;

    @GetMapping
    public String testRedis(){
        //设置值到redis
        redisTemplate.opsForValue().set("name","lucy");

        //从redis获取值
        String name = (String) redisTemplate.opsForValue().get("name");

        return name;
    }
}
